package basic.study.leetcode;

/**
 * @ClassName Mid238
 * @Description 处自身以外数组的乘积
 * @Company inspur
 * @Author Kevin
 * @Date 2020/7/9 10:46
 * @Version 1.0
 */
public class Mid238 {
    class Solution {
        public int[] productExceptSelf(int[] nums) {
            if (nums == null || nums.length == 0) {
                return null;
            }
            int[] L = new int[nums.length];
            int[] R = new int[nums.length];
            L[0] = 1;
            R[nums.length-1] = 1;
            for (int i = 1; i < nums.length; i++) {
                L[i] = L[i-1] * nums[i-1];
            }
            for (int i = nums.length-2; i >= 0; i--) {
                R[i]  = R[i+1] * nums[i+1];
            }
            int[] res = new int[nums.length];
            for (int i = 0; i < nums.length; i++) {
                res[i] = L[i] * R[i];
            }
            return res;
        }
    }
}
